LtU Forum, Site Discussion

Sun ships "extensible" Java compiler?

According to the buzz on this forum thread, Java 5.0 (nee 1.5.0) ships with a tool called "apt" (Annotation Processing Tool) that enhances the traditional javac compiler with the ability to let the user write code that examines and transforms the AST.

I assume this tool will not let you extend the Java language in arbitrary ways: it seems like apt can only parse source code that is legal Java. However, it will let you create compile-time checks for some rules that previously could only be checked at runtime. It will also likely be useful for code generation; some heavily used Java projects rely on bytecode manipulation (JDO, JBoss, Tapestry) and I suspect they could simplify their lives a lot with this.

Erlisp: Common Lisp Meets Erlang

Just found this project in a post to comp.lang.lisp : Erlisp

(...)languages like Erlang have intriguing approaches to concurrency that are easier to use and less "low-level" than this industry best practice.
Erlisp is my attempt to bring some of these ideas to Common Lisp, and perhaps develop some new approaches in the process.

It's still vaporware, but sounds definately interesting. Maybe some of our resident Erlang & Lisp gurus (Luke? ;-) could share some ideas about it.

Looking for a Solid Definition of DSL

In a discussion on mini-languages over on PerlMonks, one poster brought out a series of languages that I wouldn't consider "mini", though they do tend to be used as embedded languages inside a larger language. This poster wanted to include Turing Completeness as a requirement, stateing that if you don't, you may end up including pretty much any non-trivial OO API.

I realized from this that I don't have a good definition of "Domain Specific Language". I'm certain TC shouldn't be a requirement, but I also don't want a definition that's too broad. In the past, I went mostly by intuition; Regular Expressions in Perl "Just Feels" like a mini-language to me, but obviously this lacks rigor.

Is there an accepted definition of DSL or mini-language?

Interesting? closure/object idea

I've been designing a language for my kids to use (goal: low barrier to entry, gentle learning curve up to serious power); one of the design choices has been to make closures easy to write. {x: x+5} is equivalent to Scheme's (lambda (x) (+ x 5)); {x*y} is a closure with no arguments. A Graham accumulator would be Acc={var x=0; {x++}} (declare a variable and return a closure over it).

After reading Paul Graham's ILC 2003 talk, I started wondering how much I would need in the language to permit objects to be done as a library. Objects are equivalent to closures, but I wanted to leave room for a convenient syntax. (If nothing else, a lot of the system facilities I'll want to bind to, such as GUI toolkits, are OO, so being able to speak OO lowers the impedance mismatch.)

So, the first thing I thought of was to break encapsulation (again, this was triggered by Graham's talk), to expose the bindings contained in a closure. So, if we do C=Acc(), creating an accumulator as above, then C.x is the current value of x in the closure. Obviously, since bindings in C can also be functions, this also gives us method calls with the usual sort of syntax.

OK, so that can be used to make objects convenient. Then I started wondering about inheritance. After some false starts, I hit upon the idea of letting the right-hand argument of "." be a general expression. So, for example, C.(x+y) would be equivalent to (C.x)+(C.y). Then I could provide a closure constructor as the right-hand argument:

C2=C.{var double={x*=2}}

creates C2 as a closure created within the context of C, with access to C's bindings. This will let me (eventually) do an object library where:

class Point(x,y) {
  to moveBy(dx,dy) {
    x+=dx; y+=dy;
  }
  to abs() {
    sqrt(x*x+y*y);
  }
}
maps to:
Point=
{x,y: {
       var moveBy={dx,dy: x+=dx; y+=dy;};      
       var abs={sqrt(x*x+y*y);};
       }
 }

and:

class PointWithFlip(x,y): Point(x,y) {
  to flip() {
    var tmp=x; x=y; y=tmp;
  }
}

maps to:

PointWithFlip=
{x,y: Point(x,y).{
  var flip={var tmp=x; x=y; y=tmp;}
  }
 }

That is, to create a PointWithFlip, create a Point, and then create a new closure, containing the flip function; that new closure is the PointWithFlip.

I'm pretty happy with this idea; it should let me teach my kids closures, rather than objects as such, but without blocking them from doing OO should it be useful. And, of course, I suspect that being able to get an arbitrary expression evaluated within a closure will turn out to be pretty powerful--with that, you could do things on the fly for which OO requires a subclass. And it doesn't distort the core language much, because you have to be able to construct closures inside closures anyway.

Is this something that's been studied before? If it has, of course, I'd like to read about it before trying to implement it.

Writing a DSL for Java

The site java.net has an article on extending Java with Tasks, code blocks executing in a separate thread. This particular extension may not be very exciting, but perhaps it will introduce the idea of DSLs to a new group of programmers.

The article uses a parser generator called VisualLangLab that seems to be "Yacc with a GUI". Since the goal of the article is to extend the Java language, they need a Java grammar to start with. VisualLangLab comes with a Java 1.4 grammar, so that is what is used.

This means that the Task extension cannot be used with a 1.5 compiler; even though the extension only touches parts of the Java grammar that have not changed between 1.4 and 1.5 (I guess). Could this problem be circumvented if the standard libraries provided a representation of the grammar used in the current platform?

Language design: Escaping escapes

Most languages use special characters or special sequence of characters to denote the use of special directives. For instance, in C format strings:

"\n" denotes new line, and if you wanted to have backquote n, you'd have to write "\\n".

In VB, since " is used to delimit strings, you'd use "" to mean double quotes. eg. "He said ""Boo""!"

In each case, if you wanted to show source code in the same language, it gets very painful, since you'd have to escape escapes. For instance to show the example of <img> tag in HTML, I'd have to do this:

&lt;img src="example" &gt;

In C you'd do this:

printf("For example: printf(\"Hello World\\n\"); prints \Hello World\"\n");

Are there any languages or patterns which handle this kind of situation more elegantly?

Examples of patterns:

  1. Escaping HTML escapes is not really necessary because the user can "View source"
  2. Another example is python, which uses triple quotes """.
  3. ASP, JSP, PHP use a sequence of unusual characters eg: <php?>

Succ Zeroth International Obfuscated Haskell Code Contest Results

See the results!


Winners by Category:



Best overall entry

UlfNorell with MetaSteganoGraphicObfuscation



Best Abuse of Compiler Specific Features and Best Signature Sized Entry

DonSteward with Crawl



Most Useful submission

JeremyGibbons with PiSpigot



Thanks to everyone who entered! Please enter again next year!

Updated LtU Archive Index

Been a while since I've updated my archive index - specifically since the demise of manilla back in late June. This site is easier to index, but still I like to have access to all the thread titles on a single page. Index includes both the original archive index, as well as the new site.

In the process of doing this, I've cleared off all the original archive pages from my website. Our host has them available on the this website via the Archive. Makes more sense to have all the pages on our main site, rather than multiple copies floating around (even though I put norobot meta tags in them).

For some reason, it seems like we've been moved longer than the 3-4 months that have actually elapsed. Thanks to Anton again for the home.

Proceedings of Scheme Workshop 2004

Proceedings of the Fifth Workshop on Scheme and Functional Programming
(Workshop Program)

The proceedings from this year's Scheme Workshop, co-located with ICFP in Snowbird, Utah, are available online. The proceedings include the R6RS status report.

Laszlo - So good, I had to change my underwear

Lazlo does was Java was supposed to do -- let you run desktop-app-like applications within a browser window. But Lazlo doesn't require any plugin on its own, or flaky, slow Java. Instead, the Lazlo compiler turns Lazlo code (which is written in very fast, flexible, human-readable XML) into Flash apps. - BoingBoing

Develop applications via a highly productive declarative programming approach [...] Laszlo applications are developed via a familiar object-oriented XML markup approach that reinforces todays development best practices - Laszlo Systems

LZX is an event-driven, object-oriented language for building dynamic, data-driven applications. Because it's an XML language, LZX integrates seamlessly with your existing IDE, source control, and team development systems. - Laszlo in 10 minutes

A reliable, free, Flash development tool is really good news for amateur web designers. This will probably be a huge success.

XML feed